package userModule.component;

import java.util.ArrayList;
import java.util.List;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnData;

public class OtherRoleList extends DefaultComponent {
	@SuppressWarnings("unchecked")
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		
		List<SaturnData> rolesList = (List<SaturnData>) parameterContext.getParameterValue(0);
		List<SaturnData> userRoleList = (List<SaturnData>) parameterContext.getParameterValue(1);
		int start = (Integer)parameterContext.getParameterValue(4);
		int limit = (Integer)parameterContext.getParameterValue(5);
		
		List<SaturnData> otherRoleList = new ArrayList<SaturnData>();
		int record = 0;
		int count = 0;
		boolean flag = false;
		if(rolesList!=null){
			for(SaturnData saturnData : rolesList){
				String roleId = (String) saturnData.get("id");
				if(userRoleList!=null){
					for(SaturnData saturnData2 : userRoleList){
						String userRoleId = (String) saturnData2.get("id");
						if(userRoleId.equals(roleId)) {
							flag = true;
							record++;
							break;
						}
					}
				}
				if(!flag){
					otherRoleList.add(saturnData);
				}
				flag = false;
				count = rolesList.size() - record;
			}
		}
		
		List<SaturnData> result = new ArrayList<SaturnData>();
		
		try{
			for(int i = start; i < start + limit; i++){
				result.add(otherRoleList.get(i));
			}
		}catch(Exception e){}
		
		parameterContext.setParameter(2, result);
		parameterContext.setParameter(3, count);
	}
}